
import 'package:containerbox_study/tools_mock_date.dart';
import 'package:flutter/material.dart';

class ToolPage extends StatelessWidget {
  static const MARGIN = 8.0;
  static const INNER_MARGIN = 15.0;

        // ThemeData(
        // brightness: Brightness.dark,
        // textTheme: TextTheme(bodyText2: TextStyle(color: Colors.white))
      // ), 

  @override
  Widget build(BuildContext context) {
    List<Map<String, String>> _finacialButtons = ToolsMock.financeGrids();
    return Theme(data:
     Theme.of(context).copyWith(textTheme: TextTheme(bodyText2: TextStyle(color: Colors.red))),
      child:Scaffold(
      body: ListView(
        children: [
          _headerGirdsButtons(),
          _financialGirdViews('金融生活', _finacialButtons),
          _shopingGirdViews('购物消费', ToolsMock.shoppingGirds()),
          _serviceLifeGirdViews('生活服务', ToolsMock.serviceGirds())
        ],
      ),
    ));

  }

  Widget _headerGirdsButtons() {
    List<Map<String, String>> buttons = ToolsMock.headerGirds();
    return Container(
      height: 160,
      margin: EdgeInsets.all(MARGIN),
      decoration: BoxDecoration(
        //圆角
        borderRadius: BorderRadius.circular(4.0),
        gradient: LinearGradient( //渐变
          begin: Alignment.topCenter,
          end: Alignment.bottomCenter,
          colors: [
            Color(0xFF56AF6D),
            Color(0xFF56AA6D),
          ],
        )
      ),
      child: Center(
        child: Row(
           mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: buttons.map((item) => _getItems(item['name'].toString(), item['icon'].toString())).toList(),
        ),
      ),
    );
  }

  Widget _financialGirdViews(String title, List<Map<String, String>> buttons){
      return Container(
        child: _commonDirdViews(title, buttons),
      );
  }

  Widget _shopingGirdViews(String title, List<Map<String, String>> buttons){
      return Container(
        child: _commonDirdViews(title, buttons),
      );
  }

  Widget _serviceLifeGirdViews(String title, List<Map<String, String>> buttons){
      return Container(
        child: _commonDirdViews(title, buttons),
      );
  }

  Widget _commonDirdViews(String title, List<Map<String, String>> buttons){
    return Container(
      margin: EdgeInsets.fromLTRB(MARGIN / 2, MARGIN, MARGIN, 0),
      padding: EdgeInsets.all(MARGIN),
      decoration: BoxDecoration(borderRadius:BorderRadius.circular(4.0)),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(title, style:TextStyle(fontSize: 16), textAlign:TextAlign.left),
          SizedBox(height: 5,),
          _girdViewButtons(buttons),
        ],
      ),
      );
  }

  GridView _girdViewButtons(List<Map<String, String>> buttons){
    double space = 5.0;
    return GridView.count(
      crossAxisSpacing: space,
      mainAxisSpacing: space,
      crossAxisCount: 4,
      shrinkWrap: true,
      physics: NeverScrollableScrollPhysics(),
      children: buttons.map((item) => _getItems(item['name'].toString(), item['icon'].toString())).toList(),
      );
  }




  Widget _getItems(String title, String iconName){
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        SizedBox(
          child: Image.asset(iconName),
          width: 50,
          height: 50,
        ),
        SizedBox(
          height: 5,
        ),
        Text(title, style: TextStyle(fontSize: 14.0),)
      ],
    );
  }
}
